import React from 'react';

import './index.scss';
import UserCard from 'components/widget/user/UserCard'
import MpUrl from '@/route/getparam';
import { getCustomerList } from '@/api/user';

class UserList extends React.Component{
	constructor (props) {
		super(props)
		this.state = {
			User: '李大王',
			userList: [],
			rateName: [
				'',
				'0~50%',
				'50~80%',
				'80~90%',
				'100%'
			]
		}
	}
	componentDidMount () {
		let getUrl = new MpUrl()
		let params = {}
		if (getUrl.get('employee_id') !== undefined) {
			params.employee_id = getUrl.get('employee_id')
		} else {
			params.company_id = getUrl.get('company_id')
			params.dept = getUrl.get('dept')
		}
		params.type = getUrl.get('type')
		this.setState(params, () => {
			getCustomerList(params).then(res => {
				this.setState({
					userList: res.data
				})
			})
		})
	}
	render() {
		return(
			<div className="user-group">
				<div className="user-title">预计成交率{this.state.rateName[this.state.type]}共有{this.state.userList.length}位客户</div>
				<div className="user-list">
					{
						this.state.userList.length === 0 ? <div className='text-center'>暂无数据</div> : this.state.userList.map((item, index) => {
								return (
									<UserCard key={index} userDetail={item} />
								)
							})
					}
				</div>
			</div>
		)
	}
}
export default UserList;
